//package com.wanwu.channel.service.strategy.handle.allianpay;
//
//
//import com.wanwu.channel.common.enums.ClearStatusEnum;
//import com.wanwu.channel.common.enums.ExceptionEnum;
//import com.wanwu.channel.common.exception.SystemException;
//import com.wanwu.channel.common.util.AmountUtil;
//import com.wanwu.channel.common.util.IdGenerate;
//import com.wanwu.channel.common.util.LogUtil;
//import com.wanwu.channel.core.ClearService;
//import com.wanwu.channel.dao.entity.ChannelClearEntity;
//import com.wanwu.channel.remote.allinpay.TLHttp;
//import com.wanwu.channel.remote.allinpay.TLHttpUtils.TLRspCodx;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Service;
//
//import javax.annotation.Resource;
//import java.math.BigDecimal;
//
//import static com.wanwu.channel.remote.allinpay.TLHttp.*;
//
///**
// * @author JiWen
// * @time 2020/1/21 15:11
// * 第一步
// */
//@Service("departApplyHandler")
//public class DepartApplyHandler implements Handler {
//
//    private static Logger logger = LoggerFactory.getLogger(DepartApplyHandler.class);
//
//    @Resource
//    private ClearService clearService;
//    /**
//     * TODO 考虑注入的的方式，因为静态的时候很多参数无法注入
//     */
//    @Resource
//    private TLHttp tlHttp;
//
//    @Override
//    public void handle(AliianPayContext context) {
//        ChannelClearEntity clearEntity = context.getClearEntity();
//        String ext2 = clearEntity.getExt2();
//        if (StepEnum.DEPART_APPLY.getCode() != Integer.parseInt(ext2)) {
//            return;
//        }
//        String serialNo = IdGenerate.getOrderId();
//        DepartApplyReq departApplyReq = toCashApplyReq(clearEntity, serialNo);
//        try {
//            DepartApplyResp resp = (DepartApplyResp) request(BizTypeEnum.DEPART_APPLY, departApplyReq);
//
//            if (TLRspCodx.REQ_SUCC.equals(resp.getRspcode())) {
//                clearEntity.setExt1(resp.getApplyId());
//                clearEntity.setExt2(String.valueOf(StepEnum.DECLARE_SUBMIT.getCode()));
//            }
//            clearEntity.setThirdRespCode(resp.getRspcode());
//            clearEntity.setThirdRespMsg(resp.getRspinfo());
//            clearEntity.setClearStatus(ClearStatusEnum.PROCESS.getStatus());
//            clearService.updateChannelClear(clearEntity);
//        } catch (Exception e) {
//            LogUtil.error(logger, e, "通联资金入境申请异常");
//            throw new SystemException(ExceptionEnum.E10021);
//        }
//    }
//
//    private DepartApplyReq toCashApplyReq(ChannelClearEntity clearEntity, String serialNo) {
//        DepartApplyReq req = new DepartApplyReq();
//        req.setMeraplid(serialNo);
//        req.setGroupId("12");
//        req.setAccid(merchantEntity.getMerchantId());
//        req.setAcctno(merchantEntity.getMerchantNo());
//        req.setLockflg("B");//锁定支付金额
//        Long amount = clearEntity.getAmount();
//        req.setAmount(new BigDecimal(AmountUtil.cent2yuan(amount)));
//        req.setPayccy(clearEntity.getCurrency());
//        req.setStlccy(clearEntity.getSettCurrency());
//        req.setDeclarecode("122030");//未纳入海关统计的网络购物
//        req.setPs("");
//        req.setPurpose("");
//        req.setRemark("");
//        req.setDclmod("1");//标准格式
//        return req;
//    }
//
//}
